import { UsernameValidators } from './username.validators';
import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';

@Component({
  selector: 'sigup-form',
  templateUrl: './sigup-form.component.html',
  styleUrls: ['./sigup-form.component.css']
})
export class SigupFormComponent implements OnInit {
  form = new FormGroup({
    username: new FormControl('', [
      Validators.required,
      Validators.minLength(3),
      UsernameValidators.cannotContainSpace,
    ],UsernameValidators.shouldBeUnique),
    password: new FormControl('', Validators.required)
  });

  get username() {
    return this.form.get('username');
  }
  get password() {
    return this.form.get('password');
  }
  ngOnInit() {
  }
  login() {
    console.log(this.form.value);
    if(true){
      this.form.setErrors({invalidLogin: true});
    }
  }
}
